import {Result} from '@/base/Result';
import {request} from '@/base/Request';
import {Page} from '@/base/Page';
import {SignLog} from '@/base/model/SignLog';
import {TableSort} from "@/base/TableSort";
import {Member} from "@/base/model/Member";
import { Data, Data2, Data4} from '@/base/model/Member';

export function getSignLogList(params: {
  pageIndex: number,
  pageSize: number,
  phone?:string,
  nickname?:string,
  sortDirection?: string,
  createBegin?: string,
  createEnd?: string,
  // memberid?: number[]
}): Promise<Result<Page<SignLog>>> {
  // Object.assign(params, TableSort());
  // let memberidString = '';
  // if (params.memberid && params.memberid.length > 0) {
  //   memberidString = params.memberid.map(x => 'companyId=' + x).join('&');
  //   delete params.memberid;
  // }
  return request.getPage(SignLog, '/api/sign-log/sign?', {params});
}

export function getSignLog(id: number): Promise<Result<SignLog>> {
  return request.get(SignLog, `/api/sign-log/${id}`);
}

export function postSignLog(params: {
  memberId: string,
}): Promise<Result<SignLog>> {
  let formData = new FormData();
  Object.keys(params).forEach(x => {
    formData.append(x, params[x]);
  });
  return request.post(SignLog, '/api/sign-log', formData);
}

export function putSignLog(id: number, params: {
  memberId: string,
}): Promise<Result<SignLog>> {
  let formData = new FormData();
  Object.keys(params).forEach(x => {
    formData.append(x, params[x]);
  });
  return request.put(SignLog, `/api/sign-log/${id}`, formData);
}

export function deleteSignLog(id: number): Promise<Result<void>> {
  return request.delete(`/api/sign-log/${id}`);
}
//签到次数统计(月)
export function getSignLogUsage(params: {
  startTime: any,
  endTime: any
}) {
  return request.getArray(Data, '/api/sign-log/usage/count',{params});
}

//签到次数统计(日)
export function getSignLogUsageDaily(params: {
  startTime: any,
  endTime: any
}) {
  return request.getArray(Data2, '/api/sign-log/dailyActivityUsage/count',{params});
}
//签到积分统计
export function getSignLogComprehensive(params: {
  startTime: any,
  endTime: any,
  timeUnit: number
}) {
  return request.get(Data4, '/api/sign-log/comprehensive/statistics',{params});
}
